package de.dhbw.horb.inf2013.vierFarbenProblem.view.java2D;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.swing.JPanel;

/**
 * The Class PolygonContainer.
 */
public class PolygonContainer extends JPanel {

	/** The polygons. */
	protected Map<Integer, Polygon> polygons = new HashMap<Integer, Polygon>();

	/**
	 * Adds the polygon.
	 * 
	 * @param polygon
	 *            the polygon
	 */
	public void addPolygon(Polygon polygon) {
		this.polygons.put(polygon.getId(), polygon);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
	 */
	@Override
	public void paintComponent(Graphics g) {
		Graphics2D g2d = (Graphics2D) g;
		Set<Integer> keys = this.polygons.keySet();
		for (Integer key : keys) {
			polygons.get(key).paint(g2d);
		}

	}

	/**
	 * Count polygons.
	 * 
	 * @return the int
	 */
	public int countPolygons() {
		return polygons.size();
	}

	/**
	 * Gets the polygon.
	 * 
	 * @param id
	 *            the id
	 * @return the polygon
	 */
	public Polygon getPolygon(int id) {
		return polygons.get(id);
	}
}
